<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentStaffAdmin.class.php, $Author:  $ */



/** Staff settings
 *
 *
 * @package module.account
 * @version $Id: PhpFox_ComponentStaffAdmin.class.php 271 2008-02-01 16:14:23Z phpfoxsv $
 *
 */
class PhpFox_Mod_Account_ComponentStaffAdmin extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    $oReq = &App::getRequest();

	    if ( $oReq->get('update') )
	    {
			$aVal = $oReq->getArray('val');

			foreach($aVal as $sName => $iValue)
			{
				$iCnt = $this->oDatabase->getField("SELECT COUNT(*) FROM ". App::getT('staff_perm') ." WHERE code = '". $this->oDatabase->escape($sName) ."'");
				if ($iCnt)
				{
					$this->oDatabase->update(App::getT('staff_perm'), array('val' => $iValue), "code = '". $this->oDatabase->escape($sName) ."'");
				}
				else
				{
					$this->oDatabase->insert(App::getT('staff_perm'), array('val' => $iValue, 'code' => $sName));
				}			
			}
			App::gotoUrl('admin.config.staff', array(), App::format('Mod_Account.staff_perm_updated'), false);
	    }

		$oSecurity = App::getModuleService('Account', 'Security');

	    require_once App::getParam('path') . "site/admin/frames/menu.php";

		$aMenuItems = array();
		$aPerms = $oSecurity->getStaffListing();
		$aCachePerms = array();
		foreach($aPerms as $iKey => $aPerm)
		{
			$aCachePerms[$aPerm['code']] = $aPerm['val'];
		}
		unset($aMenu['deny']['items']['admin.main.members']);

	    foreach($aMenu as $sMenuKey => $aMenuBlock)
	    {
	        foreach($aMenuBlock['items'] as $k => $v)
	        {
	            $aMenu[$sMenuKey]['items'][$k]['val'] =  (isset($aCachePerms[$k]['val']) ? $aCachePerms[$k]['val'] : '');
	            $aMenu[$sMenuKey]['items'][$k]['id'] =  $k;

	            $aMenuItems[] = $aMenu[$sMenuKey]['items'][$k];
	        }
	    }

		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assignSrc(array(
			'aMenu' => $aMenu,
		));

		$srcHtml = $oTpl->fetch('StaffAdmin.html');
		return $srcHtml;
	}

}
?>